<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				会员卡发放记录
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="center clearfix">
				<view class="sousuo fl" @click="sousuo">
					<input type="text" placeholder="请输入用户名称" v-model="keywords" @confirm="sousuo" />
					<image :src="baseUrl + '/wximage/sousuo.png'" @click="sousuo"></image>
				</view>
				<view class="shaixuan fr clearfix" @click="shaixuan">
					<image :src="baseUrl + '/wximage/shaixuan.png'" class="fl"></image>
					<view class="name fl">筛选</view>
				</view>
			</view>
			<view class="bottom">
				<view class="shang">
					<view class="name">月卡：<text class="color">{{dataList.yueka}}</text>张</view>
					<view class="name">季卡：<text class="color">{{dataList.jika}}</text>张</view>
					<view class="name">年卡：<text class="color">{{dataList.nianka}}</text>张</view>
				</view>
				<view class="shang xia">
					<view class="name">两年卡：<text class="color">{{dataList.twonianka}}</text>张</view>
					<view class="name">三年卡：<text class="color">{{dataList.threenianka}}</text>张</view>
				</view>
			</view>
		</view>
		<view class="morebeijing" v-if="morebjstatus" @click="guanbi"></view>
		<view class="moretankuang" v-if="morestatus">
			<view class="bankuai">
				<view class="top">时间选择</view>
				<view class="time">
					<text>{{sdatelabel}}</text>至<text>{{edatelabel}}</text>
				</view>
				<view class="bottom clearfix">
					<text @click="show = true">开始时间</text>
					<text @click="show = true">结束时间</text>
				</view>
				<u-calendar v-model="show" :mode="mode" toolTip="时间选择" @change="change"></u-calendar>
			</view>
			<view class="bankuai">
				<view class="top">会员卡状态</view>
				<view class="bottom clearfix">
					<text :class="[statusIndex==0?'active':'']" @click="statusIndex = 0">全部</text>
					<text :class="[statusIndex==1?'active':'']" @click="statusIndex = 1">已发放</text>
					<text :class="[statusIndex==2?'active':'']" @click="statusIndex = 2">已失效</text>
				</view>
			</view>
			<view class="bankuai">
				<view class="top">会员卡类型</view>
				<view class="bottom bottomts clearfix">
					<text :class="[attrIndex==0?'active':'']" @click="attrIndex = 0">全部</text>
					<text :class="[attrIndex==1?'active':'']" @click="attrIndex = 1">月卡</text>
					<text :class="[attrIndex==2?'active':'']" @click="attrIndex = 2">季卡</text>
					<text :class="[attrIndex==3?'active':'']" @click="attrIndex = 3">年卡</text>
					<text :class="[attrIndex==4?'active':'']" @click="attrIndex = 4">两年卡</text>
					<text :class="[attrIndex==5?'active':'']" @click="attrIndex = 5">三年卡</text>
				</view>
			</view>
			<view class="queren" @click="queren">
				确认
			</view>
		</view>
		<view class="content" v-if="list.length != 0">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="top clearfix">
					<view class="title fl" v-if="item.charge_leixing == 1">普通宝、快充宝</view>
					<view class="title fl" v-if="item.charge_leixing == 2">普通宝</view>
					<view class="title fl" v-if="item.charge_leixing == 3">快充宝</view>
					<view class="money fr">{{item.title}}</view>
				</view>
				<view class="center">
					<view class="desc">会员名称：{{item.usersname}}</view>
					<view class="desc">会员ID：{{item.member_card}}</view>
					<view class="desc">商户名称：{{item.bussiness_name}}</view>
					<view class="desc" v-if="item.jm_leixing == 1">单次可使用时长：{{item.shichang}}小时</view>
					<view class="desc" v-if="item.jm_leixing == 2">单次减免金额：{{item.jm_leixing}}元</view>
					<view class="desc">单日可用次数：{{item.cishu}}次</view>
					<view class="desc">有效期：{{item.daoqi_time}}</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				keywords: '',
				statusIndex: 0,
				attrIndex: 0,
				list: [],
				morebjstatus: false,
				morestatus: false,
				show: false,
				mode: 'range',
				sdate: '',
				edate: '',
				sdatelabel: '--',
				edatelabel: '--',
				page: 1,
				pageSize: 10,
				total: 0,
				bussiness_id: '',
				dataList: {
					yueka: 0,
					jika: 0,
					nianka: 0,
					twonianka: 0,
					threenianka: 0,
				}
			}
		},
		onLoad(options) {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			if(options.bussiness_id){
				this.bussiness_id = options.bussiness_id;
			}
			
			// 发放数据统计
			this.request({
				url: '/xcx/membershipcardtongji',
				data: {
					czz_id: uni.getStorageSync('agent_id'),
					bussiness_id: this.bussiness_id,
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					this.dataList = res.data.data;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
			
			// 发放记录
			this.total = 0;
			this.page = 1;
			this.list = [];
			this.getList(this.bussiness_id, this.sdate, this.edate, this.attrIndex, this.statusIndex, this.keywords, this.page, this.pageSize);
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page = this.page + 1;
		
				this.getList(this.bussiness_id, this.sdate, this.edate, this.attrIndex, this.statusIndex, this.keywords, this.page, this.pageSize);
			}
		},
		methods: {
			getList(bussiness_id,sdate,edate,attrIndex,statusIndex,keywords,page,pageSize){
				this.request({
					url: '/xcx/membershipcardrecord',
					data: {
						czz_id: uni.getStorageSync('agent_id'),
						bussiness_id: bussiness_id,
						sdate: sdate,
						edate: edate,
						attrIndex: attrIndex,
						statusIndex: statusIndex,
						keywords: keywords,
						page: page,
						pageSize: pageSize,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.total = res.data.data.total;
						this.list = this.list.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			queren(){
				this.morebjstatus = !this.morebjstatus;
				this.morestatus = !this.morestatus;
				
				this.page = 1;
				this.pageSize = 10;
				this.total = 0;
				this.list = [];
				
				this.getList(this.bussiness_id, this.sdate, this.edate, this.attrIndex, this.statusIndex, this.keywords, this.page, this.pageSize);
			},
			sousuo(){
				this.page = 1;
				this.pageSize = 10;
				this.total = 0;
				this.list = [];
				
				this.getList(this.bussiness_id, this.sdate, this.edate, this.attrIndex, this.statusIndex, this.keywords, this.page, this.pageSize);
			},
			shaixuan(){
				this.morebjstatus = !this.morebjstatus;
				this.morestatus = !this.morestatus;
			},
			guanbi(){
				this.morebjstatus = false;
				this.morestatus = false;
				
				this.sdate = '';
				this.edate = '';
				this.sdatelabel = '--';
				this.edatelabel = '--';
				this.attrIndex = 0;
				this.statusIndex = 0;
			},
			change(e) {
				this.sdate = e.startDate;
				this.edate = e.endDate;
				
				this.sdatelabel = e.startDate;
				this.edatelabel = e.endDate;
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f9f9ff;
	}
	
	.equipment {
		width: 100%;
		margin: 0 auto;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 20rpx 0;
			box-sizing: border-box;
			position: relative;
			
			.center{
				width: 100%;
				padding: 0 20rpx;
				box-sizing: border-box;
				
				.shaixuan {
					width: 116rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 10rpx;
				
					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
						margin-right: 6rpx;
					}
				
					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
				
				.sousuo {
					width: 80%;
					box-sizing: border-box;
					position: relative;
						
					input {
						width: 100%;
						height: 60rpx;
						line-height: 60rpx;
						background: #ffffff;
						border-radius: 30rpx;
						padding-left: 30rpx;
						color: #999999;
						box-sizing: border-box;
					}
						
					image {
						width: 72rpx;
						height: 40rpx;
						position: absolute;
						right: 10rpx;
						top: 10rpx;
						z-index: 10;
					}
				}
			}
			
			.bottom{
				width: 100%;
				margin: 0 auto;
				background: #ffffff;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
				border-radius: 20rpx;
				margin-top: 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				
				.shang{
					border-bottom: 1rpx solid #D8D8D8;
					padding-bottom: 20rpx;
					
					.name{
						display: inline-block;
						font-size: 24rpx;
						color: #333333;
						font-weight: 700;
						margin-right: 70rpx;
					}
					
					.color{
						color: #5C88FA;
					}
					
					.name:nth-of-type(3n){
						margin-right: 0;
					}
				}
				
				.xia{
					padding-bottom: 0;
					padding-top: 20rpx;
					border: none;
				}
			}
		}
		
		.content{
			width: 100%;
			padding: 0 20rpx;
			box-sizing: border-box;
			margin-top: -20rpx;
			position: absolute;
			
			.list{
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 26rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
				
				.top{
					width: 100%;
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 20rpx;
					
					.title{
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
					}
					
					.money{
						font-size: 28rpx;
						color: #8B8CFF;
						margin-right: 8rpx;
						font-weight: 700;
					}
				}
				
				.center{
					width: 96%;
					margin: 0 auto;
					margin-top: 20rpx;
					
					.desc{
						width: 90%;
						font-size: 24rpx;
						color: #333333;
						line-height: 44rpx;
					}
					
					.color{
						font-size: 24rpx;
						color: #5C88FA;
					}
				}
			}
		}
		
		.empty{
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
		
		.morebeijing{
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}
		
		.moretankuang{
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 1000rpx;
			background: #fff;
			z-index: 200;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			padding: 20rpx 0;
			
			.bankuai{
				
				.top{
					background: #FDFDFD;
					font-size: 32rpx;
					color: #333333;
					height: 72rpx;
					line-height: 72rpx;
					padding-left: 40rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #DFE6FF;
				}
				
				.time{
					margin-top: 20rpx;
					margin-left: 40rpx;
					font-size: 24rpx;
					color: #333333;
					
					text:nth-of-type(1){
						font-size: 24rpx;
						color: #FA5E5C;
					}
					
					text:nth-of-type(2){
						font-size: 24rpx;
						color: #5C88FA;
					}
				}
				
				.bottom{
					margin-top: 40rpx;
					margin-bottom: 50rpx;
					
					text{
						display: inline-block;
						margin-left: 60rpx;
						width: 160rpx;
						height: 54rpx;
						text-align: center;
						border-radius: 16rpx;
						line-height: 54rpx;
						background: #F6F6F6;
						font-size: 24rpx;
						color: #333333;
					}
					
					.active{
						background: #E3F2FF;
					}
				}
				
				.bottomts{
					
					text{
						margin-bottom: 20rpx;
					}
				}
			}
			
			.queren{
				width: 180rpx;
				margin: 0 auto;
				height: 60rpx;
				line-height: 60rpx;
				border-radius: 16rpx;
				text-align: center;
				background: #3B91F8;
				margin-top: 30rpx;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
		
		.beijing{
			position: absolute;
			top: 250rpx;
			left: 0;
			width: 100%;
			height: 78vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}
		
		.tankuang{
			position: absolute;
			top: 250rpx;
			left: 0;
			width: 100%;
			height: 400rpx;
			background: #fff;
			overflow-y: scroll;
			z-index: 200;
			border-bottom-left-radius: 20rpx;
			border-bottom-right-radius: 20rpx;
			padding: 20rpx 0;
			
			.liebiao{
				width: 100%;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				position: relative;
				
				.wenzi{
					font-size: 24rpx;
					color: #999999;
				}
				
				image{
					width: 100%;
					height: 72rpx;
					position: absolute;
					top: 0;
					left: 0;
				}
			}
		}
	}
</style>